package com.weixing.mall.core.support.auth;


import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

/**
 * 获取session中的值
 *
 * @author zhangkeyuan
 */
public class AuthInfoArgsResolver implements HandlerMethodArgumentResolver {

    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return parameter.hasParameterAnnotation(SysInfo.class)
                || parameter.hasParameterAnnotation(MemInfo.class)
                || parameter.hasParameterAnnotation(AgentInfo.class);
    }

    @Override
    public Object resolveArgument(MethodParameter parameter,
                                  ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
                                  WebDataBinderFactory binderFactory) throws Exception {
        Object annoVal = null;
        if (parameter.getParameterAnnotation(SysInfo.class) != null) {
            annoVal = AuthUtil.getSysExt();
        } else if (parameter.getParameterAnnotation(MemInfo.class) != null) {
            annoVal = AuthUtil.getMemberExt();
        } else if (parameter.getParameterAnnotation(AgentInfo.class) != null) {
            annoVal = AuthUtil.getAgentExt();
        }
        return annoVal;
    }

}